﻿using System;
using NUnit.Framework;
using QuickBencher.Repositories;

namespace QuickBencher.Test.Repositories
{
	public class MeasurementDTOTests
	{
		[TestFixture]
		public class When_created
		{
			[Test]
			public void Then_assure_Timestamp_is_set()
			{
				var dto = new MeasurementDTO();

				Assert.AreEqual(DateTime.Now, dto.Timestamp);
			}
		}

		[TestFixture]
		public class When_Label_is_set
		{
			private MeasurementDTO dto;

			[SetUp]
			public void Setup()
			{
				dto = new MeasurementDTO();
			}

			[Test]
			public void Then_assure_a_valid_id_can_be_generated_based_on_Label()
			{
				dto.Label = "Service - FindCustomer";

				Assert.AreEqual("Service-FindCustomer", dto.Id);
			}

			[Test]
			public void Then_a_assure_a_valid_id_can_be_generated_if_label_contains_lots_of_whitespace()
			{
				dto.Label = "ClientService -      FindCustomer, just trying something";

				Assert.AreEqual("ClientService-FindCustomerjusttryingsomething", dto.Id);
			}

			[Test]
			public void Then_assure_a_valid_id_can_be_generated_if_label_contains_tabs()
			{
				dto.Label = "Service	 -		  FindCustomer";
				
				Assert.AreEqual("Service-FindCustomer", dto.Id);
			}

			[Test]
			public void Then_assure_only_chars_are_used_in_id()
			{
				dto.Label = "Services-:..!2´@@!**@@@+++??((==()))FindCustomer^$%#/ ¨_~";
				
				Assert.AreEqual("Services-2FindCustomer", dto.Id);
			}
		}

		[TestFixture]
		public class When_Label_is_not_set
		{
			[Test]
			public void Then_assure_a_default_id_is_generated()
			{
				var dto = new MeasurementDTO();

				Assert.AreEqual("no-name", dto.Id);
			}
		}
	}
}
